package task.factory;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import task.AbstractAutomatonTask;
import task.config.AbstractAutomatonTaskConfig;

/**
 * 
 * @author Daniil Chivilikhin
 *
 */
public class TaskFactory {
	private AbstractAutomatonTaskConfig config;
	
	public TaskFactory(AbstractAutomatonTaskConfig config) {
		this.config = config;
	}
	
	public AbstractAutomatonTask createTask() {
		try {
			Class taskClass = Class.forName(config.className());
			Constructor taskConstructor = taskClass.getConstructor(new Class[]{AbstractAutomatonTaskConfig.class});
			return (AbstractAutomatonTask) taskConstructor.newInstance(config);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return null;
	}

}
